//
//  NewViewController.m
//  ThePrivateKitchen
//
//  Created by lirui on 16/1/20.
//  Copyright © 2016年 www.lanou3g.com蓝鸥科技. All rights reserved.
//

#import "NewViewController.h"
#import <AVFoundation/AVFoundation.h>
#import <AVKit/AVKit.h>

@interface NewViewController ()
@property (nonatomic, retain) AVPlayer *videoPlayer;
@property (nonatomic, retain) AVPlayerViewController *playerViewController;

@end

@implementation NewViewController

- (void)dealloc
{
    [_string release];
    [_videoPlayer release];
    [_playerViewController release];
    [super dealloc];
}
//视图将要出现的时候隐藏tabbar
- (void)viewWillAppear:(BOOL)animated
{
    //tabBar隐藏
    self.tabBarController.tabBar.hidden = YES;
}
//视图将要消失的时候播放器关闭
- (void)viewWillDisappear:(BOOL)animated
{
    [self.playerViewController.player pause];
    self.tabBarController.tabBar.hidden = NO;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor =[ UIColor redColor];
    [self creatVideoPlayer:self.string];
        NSLog(@"%@",self.string);
   
}
-(void)creatVideoPlayer:(NSString *)str
{
    NSURL *url = [NSURL URLWithString:str];
    AVAsset *movieAsset = [AVURLAsset URLAssetWithURL:url options:nil];
    
    AVPlayerItem *item = [AVPlayerItem playerItemWithAsset:movieAsset];
    
    self.videoPlayer = [AVPlayer playerWithPlayerItem:item];
    
    AVPlayerLayer *layer = [AVPlayerLayer playerLayerWithPlayer:self.videoPlayer];
    
    self.playerViewController = [[AVPlayerViewController alloc] init];
    self.playerViewController.view.frame = CGRectMake(0, 0, WIDTH * 375, HEIGHT *667);
    [self.view addSubview:self.playerViewController.view];
    [self.view.layer addSublayer:layer];
    
    self.playerViewController.player = self.videoPlayer;
    
    [self.playerViewController.player play];
    

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
